import java.io.File;
import java.io.IOException;
import java.util.concurrent.*;

/**
 * Created by cc on 2016/12/26.
 */
public class Test {

    public static void main(String[] args) throws IOException {
        Callable<String> task = new Callable<String>() {
            @Override
            public String call() throws Exception {
                Thread.sleep(4000);
                System.out.println("exec success");
                return "Success";
            }
        };

        ExecutorService executorService = Executors.newSingleThreadExecutor();
        Future<String> future = executorService.submit(task);
        try {
            String result = future.get(3, TimeUnit.SECONDS);
            System.out.println(result);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (TimeoutException e) {
            e.printStackTrace();
        }
    }


}
